//
//  RankingCellViewModel.swift
//  SLQuickReader
//
//  Created by ALin on 2017/8/22.
//  Copyright © 2017年 ALin. All rights reserved.
//

import UIKit
import Kingfisher

class RankingCellViewModel: BaseViewModel, BaseView {
    var book: Book!
    func bind(to view: UIView...) {
        guard let cell = (view.first as? RankingCell) else {
            return
        }
        cell.iconView.kf.setImage(with: URL(string: (book.cover?.fullImage())!))
        cell.bookNameLabel.text = book.title
        cell.authorLabel.text = book.author
        cell.desLabel.text = book.shortIntro
        let str: NSString = "\(String(format: "%.2f", book.latelyFollower))万人气 丨 \(book.retentionRatio ?? "30")%存留率" as NSString
        let length = book.retentionRatio!.characters.count + 1
        let attributedStr = NSMutableAttributedString(string: str as String)
        attributedStr.setAttributes([NSForegroundColorAttributeName: UIColor.red], range: NSRange(location: 0, length: str.range(of: "万").location))
        attributedStr.setAttributes([NSForegroundColorAttributeName: UIColor.red], range: NSRange(location: str.range(of: "存").location - length, length: length))
        cell.othersLabel.attributedText = attributedStr
    }
}
